package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.CouponModel;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by Administrator on 2016/1/9.
 */
public class MyCouponAdapter extends BaseAdapter{

    private Context context;
    private LayoutInflater inflater;
    private List<CouponModel>couponModelList;

    public MyCouponAdapter(){

    }

    public MyCouponAdapter(Context context, List<CouponModel>couponModelList){
        this.context=context;
        this.couponModelList=couponModelList;
        inflater=LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return couponModelList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        HolderView holder=null;
        if (view==null){
            holder=new HolderView();
            view=inflater.inflate(R.layout.item_list_mycoupon,null);
            holder.text_money_num=(TextView)view.findViewById(R.id.text_money_num);
            holder.text_reason=(TextView)view.findViewById(R.id.text_reason);
            holder.text_name=(TextView)view.findViewById(R.id.text_name);
            holder.text_ticket=(TextView)view.findViewById(R.id.text_ticket);
            holder.text_data=(TextView)view.findViewById(R.id.text_data);
            view.setTag(holder);
        }else{
            holder=(HolderView) view.getTag();
        }

        Double value= Double.valueOf(couponModelList.get(position).getValue());
        holder.text_money_num.setText(new DecimalFormat("0.00").format(value));
        holder.text_reason.setText("满"+couponModelList.get(position).getCondition()+"减"+couponModelList.get(position).getValue());
        holder.text_name.setText(couponModelList.get(position).getName());
        holder.text_ticket.setText("券号:"+couponModelList.get(position).getNumber());
        String mStarttime = couponModelList.get(position).getStartDate();
        String mEndtime = couponModelList.get(position).getEndDate();
        holder.text_data.setText(mStarttime+" - "+mEndtime);

        return view;
    }

    public static class HolderView{
        TextView text_money_num,text_reason,text_name,text_ticket,text_data;
    }
}
